package ve.usb.coord.colision;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import ve.usb.cohesion.runtime.CohesionAction;

import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import ve.usb.coord.colision.hibernate.*;


/**
 * Manejo de elementos de la entidad Oferta.<br>
 */
public class AccionesOferta extends CohesionAction {
    
/**
     * Acción llamada por Struts para ejecutar la acción OfertaBuscarI.
     * Prepara la vista de selección de criterios de búsqueda para una entidad.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward OfertaBuscarI(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        //Salidas
        final String SALIDA_0 = "ofertaBuscar";

        String salida = SALIDA_0;        
        Session s = HibernateUtil.getSessionFactory().getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {

            HttpSession sess = request.getSession();
            {FOfertaBuscar fFOfertaBuscar = (FOfertaBuscar)sess.getAttribute("FOfertaBuscar");
             if (fFOfertaBuscar==null) {
                 fFOfertaBuscar = new FOfertaBuscar();
                 sess.setAttribute("FOfertaBuscar", fFOfertaBuscar);
             } else {
                 fFOfertaBuscar.reset(mapping, request);
             }
            }

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        }
        return mapping.findForward(salida);
    }

/**
     * Acción llamada por Struts para ejecutar la acción OfertaCrearI.
     * Prepara la vista de captura de datos de una entidad para realizar una inserción.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward OfertaCrearI(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        //Salidas
        final String SALIDA_0 = "ofertaCrear";

        String salida = SALIDA_0;        
        Session s = HibernateUtil.getSessionFactory().getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {

            HttpSession sess = request.getSession();
            {FOferta fFOferta = (FOferta)sess.getAttribute("FOferta");
             if (fFOferta==null) {
                 fFOferta = new FOferta();
                 sess.setAttribute("FOferta", fFOferta);
             } else {
                 fFOferta.reset(mapping, request);
             }

             //Feed for combo listPeriodo.
             {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
                (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
                "select new ve.usb.cohesion.runtime.Pair(nombre, idPeriodo) " + 
                "from Periodo").list();
              list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
              fFOferta.setListPeriodo(list);
             }
             if(Integer.parseInt(sess.getAttribute("tipoUsuario").toString()) != 0){
             //Feed for combo listPlanDeEstudios.
               {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
                (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
                "select new ve.usb.cohesion.runtime.Pair(carrera, idPlan) " + 
                "from PlanDeEstudios where coordinacion = "+request.getParameter("idCoordinacion")).list();
                list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
                fFOferta.setListPlanDeEstudios(list);
               }
             //Feed for combo listRequisitos.
               {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
                (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
                "select new ve.usb.cohesion.runtime.Pair(asignatura.codigo, idRequisito) " + 
                "from Requisitos where grupo.planDeEstudios.coordinacion = "+request.getParameter("idCoordinacion")).list();
                list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
                fFOferta.setListRequisitos(list);
               }
             }else{
             //Feed for combo listPlanDeEstudios.
               {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
                (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
                "select new ve.usb.cohesion.runtime.Pair(carrera, idPlan) " + 
                "from PlanDeEstudios").list();
                list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
                fFOferta.setListPlanDeEstudios(list);
               }
             //Feed for combo listRequisitos.
               {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
                (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
                "select new ve.usb.cohesion.runtime.Pair(asignatura.codigo, idRequisito) " + 
                "from Requisitos").list();
                list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
                fFOferta.setListRequisitos(list);
               }
             }
            }

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        }
        return mapping.findForward(salida);
    }

/**
     * Acción llamada por Struts para ejecutar la acción OfertaBuscar.
     * Captura los criterios de búsqueda y los fija en la sesión.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward OfertaBuscar(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        //Salidas
        final String SALIDA_0 = "OfertaListarI";

        String salida = SALIDA_0;        
        Session s = HibernateUtil.getSessionFactory().getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            FOfertaBuscar fFOfertaBuscar = (FOfertaBuscar)form;

            request.getSession().setAttribute("OfertaBuscar", " where periodo like '%" + fFOfertaBuscar.getPeriodo() + "%'");

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        }
        return mapping.findForward(salida);
    }

/**
     * Acción llamada por Struts para ejecutar la acción OfertaListarI.
     * Selecciona las entidades a ser listadas de acuerdo a los parámetros recibidos.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward OfertaListarI(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        //Salidas
        final String SALIDA_0 = "ofertaListar";

        String salida = SALIDA_0;        
        Session s = HibernateUtil.getSessionFactory().getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {

            String crit = (String)request.getSession().getAttribute("OfertaBuscar");
            if(Integer.parseInt(request.getSession().getAttribute("tipoUsuario").toString()) != 0){
                if (crit==null) crit = " where planDeEstudios.coordinacion = "+request.getParameter("idCoordinacion");
                else request.getSession().removeAttribute("OfertaBuscar");
            }else{
                if (crit==null) crit = "";
                else request.getSession().removeAttribute("OfertaBuscar");
            }
            java.util.List<Oferta> list = (java.util.List<Oferta>)s.createQuery("from Oferta"+crit).list();
            request.setAttribute("L_Oferta", list);
            for (Oferta oferta:list) {
                if (oferta.getPeriodo()!=null) oferta.getPeriodo().getNombre();
            }
            for (Oferta oferta:list) {
                if (oferta.getPlanDeEstudios()!=null) oferta.getPlanDeEstudios().getCoordinacion();
            }
            for (Oferta oferta:list) {
                if (oferta.getRequisito()!=null) oferta.getRequisito().getAsignatura().getCodigo();
            }


            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        }
        return mapping.findForward(salida);
    }

/**
     * Acción llamada por Struts para ejecutar la acción OfertaI.
     * Prepara la vista de actualización de una entidad.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward OfertaI(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        //Salidas
        final String SALIDA_0 = "oferta";

        String salida = SALIDA_0;        
        Session s = HibernateUtil.getSessionFactory().getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {

            String id = request.getParameter("idOferta");
            Long idOferta = (id==null) ? 
                (Long)request.getSession().getAttribute("idOferta") :
                new Long(id);
            
            HttpSession sess = request.getSession();
            FOferta fFOferta = (FOferta)sess.getAttribute("FOferta");
            if (fFOferta==null) {
                fFOferta = new FOferta();
                sess.setAttribute("FOferta", fFOferta);
            } else {
                fFOferta.reset(mapping, request);
            }
            Oferta oferta = (Oferta)s.load(Oferta.class, idOferta);
            fFOferta.setIdOferta(oferta.getIdOferta());
            if (oferta.getPeriodo()!=null) {
                fFOferta.setPeriodo(oferta.getPeriodo().getIdPeriodo());
            } else {
                fFOferta.setPeriodo(0);
            }
            if (oferta.getPlanDeEstudios()!=null) {
                fFOferta.setPlanDeEstudios(oferta.getPlanDeEstudios().getIdPlan());
            } else {
                fFOferta.setPlanDeEstudios(0);
            }
            if (oferta.getRequisito()!=null) {
                fFOferta.setRequisito(oferta.getRequisito().getIdRequisito());
            } else {
                fFOferta.setRequisito(0);
            }

            //Feed for combo listPeriodo.
            {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
               (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
               "select new ve.usb.cohesion.runtime.Pair(nombre, idPeriodo) " + 
               "from Periodo").list();
             list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
             fFOferta.setListPeriodo(list);
            }
            if(Integer.parseInt(sess.getAttribute("tipoUsuario").toString()) != 0){
             //Feed for combo listPlanDeEstudios.
               {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
                (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
                "select new ve.usb.cohesion.runtime.Pair(carrera, idPlan) " + 
                "from PlanDeEstudios where coordinacion = "+request.getParameter("idCoordinacion")).list();
                list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
                fFOferta.setListPlanDeEstudios(list);
               }
             //Feed for combo listRequisitos.
               {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
                (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
                "select new ve.usb.cohesion.runtime.Pair(asignatura.codigo, idRequisito) " + 
                "from Requisitos where grupo.planDeEstudios.coordinacion = "+request.getParameter("idCoordinacion")).list();
                list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
                fFOferta.setListRequisitos(list);
               }
             }else{
             //Feed for combo listPlanDeEstudios.
               {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
                (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
                "select new ve.usb.cohesion.runtime.Pair(carrera, idPlan) " + 
                "from PlanDeEstudios").list();
                list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
                fFOferta.setListPlanDeEstudios(list);
               }
             //Feed for combo listRequisitos.
               {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
                (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
                "select new ve.usb.cohesion.runtime.Pair(asignatura.codigo, idRequisito) " + 
                "from Requisitos").list();
                list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
                fFOferta.setListRequisitos(list);
               }
             }

            Hibernate.initialize(oferta.getHorario());
            
            for(Horario horario:oferta.getHorario()){
               
            }
            
            //Feed for combo listRequisitos.
            java.util.List ofertas = s.createQuery("from Horario where oferta = " + oferta.getIdOferta() + " order by tipoHora DESC,dia,hora").list();
            request.setAttribute("L_Horario", ofertas);
            
            Hibernate.initialize(oferta.getRequisito().getAsignatura());
            request.setAttribute("D_Asignatura", oferta.getRequisito().getAsignatura());
            
            request.getSession().setAttribute("idOferta", idOferta);

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        }
        return mapping.findForward(salida);
    }

/**
     * Acción llamada por Struts para ejecutar la acción OfertaAct.
     * Registro de actualizaciones de una entidad.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward OfertaAct(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        //Salidas
        final String SALIDA_0 = "oferta";

        String salida = SALIDA_0;        
        Session s = HibernateUtil.getSessionFactory().getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            FOferta fFOferta = (FOferta)form;

            Oferta oferta = (Oferta)s.load(Oferta.class, new Long(fFOferta.getIdOferta()));
            if (fFOferta.getPeriodo()==0) oferta.setPeriodo(null);
            else if ((oferta.getPeriodo()==null) ||
                    (oferta.getPeriodo().getIdPeriodo()!=fFOferta.getPeriodo())) {
                Periodo obj = (Periodo)s.load(Periodo.class, fFOferta.getPeriodo());
                oferta.setPeriodo(obj);
            }
            if (fFOferta.getPlanDeEstudios()==0) oferta.setPlanDeEstudios(null);
            else if ((oferta.getPlanDeEstudios()==null) ||
                    (oferta.getPlanDeEstudios().getIdPlan()!=fFOferta.getPlanDeEstudios())) {
                PlanDeEstudios obj = (PlanDeEstudios)s.load(PlanDeEstudios.class, fFOferta.getPlanDeEstudios());
                oferta.setPlanDeEstudios(obj);
            }
            if (fFOferta.getRequisito()==0) oferta.setRequisito(null);
            else if ((oferta.getRequisito()==null) ||
                    (oferta.getRequisito().getIdRequisito()!=fFOferta.getRequisito())) {
                Requisitos obj = (Requisitos)s.load(Requisitos.class, fFOferta.getRequisito());
                oferta.setRequisito(obj);
            }


            //Feed for combo listPeriodo.
            {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
               (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
               "select new ve.usb.cohesion.runtime.Pair(nombre, idPeriodo) " + 
               "from Periodo").list();
             list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
             fFOferta.setListPeriodo(list);
            }
            if(Integer.parseInt(request.getSession().getAttribute("tipoUsuario").toString()) != 0){
             //Feed for combo listPlanDeEstudios.
               {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
                (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
                "select new ve.usb.cohesion.runtime.Pair(carrera, idPlan) " + 
                "from PlanDeEstudios where coordinacion = "+request.getParameter("idCoordinacion")).list();
                list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
                fFOferta.setListPlanDeEstudios(list);
               }
             //Feed for combo listRequisitos.
               {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
                (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
                "select new ve.usb.cohesion.runtime.Pair(asignatura.codigo, idRequisito) " + 
                "from Requisitos where grupo.planDeEstudios.coordinacion = "+request.getParameter("idCoordinacion")).list();
                list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
                fFOferta.setListRequisitos(list);
               }
             }else{
             //Feed for combo listPlanDeEstudios.
               {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
                (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
                "select new ve.usb.cohesion.runtime.Pair(carrera, idPlan) " + 
                "from PlanDeEstudios").list();
                list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
                fFOferta.setListPlanDeEstudios(list);
               }
             //Feed for combo listRequisitos.
               {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
                (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
                "select new ve.usb.cohesion.runtime.Pair(asignatura.codigo, idRequisito) " + 
                "from Requisitos").list();
                list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
                fFOferta.setListRequisitos(list);
               }
             }

            Hibernate.initialize(oferta.getHorario());
            request.setAttribute("L_Horario", oferta.getHorario());
            
            Hibernate.initialize(oferta.getRequisito().getAsignatura());
            request.setAttribute("D_Asignatura", oferta.getRequisito().getAsignatura());

            request.getSession().setAttribute("idOferta", oferta.getIdOferta());

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        }
        return mapping.findForward(salida);
    }

/**
     * Acción llamada por Struts para ejecutar la acción OfertaElim.
     * Elimina la entidad seleccionada.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward OfertaElim(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        //Salidas
        final String SALIDA_0 = "OfertaListarI";
        final String SALIDA_1 = "oferta";

        String salida = SALIDA_0;        
        Session s = HibernateUtil.getSessionFactory().getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {

            String id = request.getParameter("idOferta");
            Long idOferta = (id==null) ? 
                (Long)request.getSession().getAttribute("idOferta") :
                new Long(id);
            Oferta oferta = (Oferta)s.load(Oferta.class, idOferta);
            s.delete(oferta);
            try {
                s.flush();
            } catch (Exception ex1) {
                ex1.printStackTrace();
                salida = SALIDA_1;
                request.setAttribute("msg", "No se pudo eliminar entidad.");
            }

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        }
        return mapping.findForward(salida);
    }

/**
     * Acción llamada por Struts para ejecutar la acción OfertaCrear.
     * Registro de la creación de una oferta.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward OfertaCrear(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        //Salidas
        final String SALIDA_1 = "oferta";

        String salida = SALIDA_1;        
        Session s = HibernateUtil.getSessionFactory().getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            FOferta fFOferta = (FOferta)form;

            Oferta oferta = new Oferta();
            if (fFOferta.getPeriodo()==0) oferta.setPeriodo(null);
            else if ((oferta.getPeriodo()==null) ||
                    (oferta.getPeriodo().getIdPeriodo()!=fFOferta.getPeriodo())) {
                Periodo obj = (Periodo)s.load(Periodo.class, fFOferta.getPeriodo());
                oferta.setPeriodo(obj);
            }
            if (fFOferta.getPlanDeEstudios()==0) oferta.setPlanDeEstudios(null);
            else if ((oferta.getPlanDeEstudios()==null) ||
                    (oferta.getPlanDeEstudios().getIdPlan()!=fFOferta.getPlanDeEstudios())) {
                PlanDeEstudios obj = (PlanDeEstudios)s.load(PlanDeEstudios.class, fFOferta.getPlanDeEstudios());
                oferta.setPlanDeEstudios(obj);
            }
            if (fFOferta.getRequisito()==0) oferta.setRequisito(null);
            else if ((oferta.getRequisito()==null) ||
                    (oferta.getRequisito().getIdRequisito()!=fFOferta.getRequisito())) {
                Requisitos obj = (Requisitos)s.load(Requisitos.class, fFOferta.getRequisito());
                oferta.setRequisito(obj);
            }

            s.save(oferta);
            s.flush();
            fFOferta.setIdOferta(oferta.getIdOferta());

            //Feed for combo listPeriodo.
            {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
               (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
               "select new ve.usb.cohesion.runtime.Pair(nombre, idPeriodo) " + 
               "from Periodo").list();
             list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
             fFOferta.setListPeriodo(list);
            }
            if(Integer.parseInt(request.getSession().getAttribute("tipoUsuario").toString()) != 0){
             //Feed for combo listPlanDeEstudios.
               {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
                (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
                "select new ve.usb.cohesion.runtime.Pair(carrera, idPlan) " + 
                "from PlanDeEstudios where coordinacion = "+request.getParameter("idCoordinacion")).list();
                list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
                fFOferta.setListPlanDeEstudios(list);
               }
             //Feed for combo listRequisitos.
               {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
                (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
                "select new ve.usb.cohesion.runtime.Pair(asignatura.codigo, idRequisito) " + 
                "from Requisitos where grupo.planDeEstudios.coordinacion = "+request.getParameter("idCoordinacion")).list();
                list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
                fFOferta.setListRequisitos(list);
               }
             }else{
             //Feed for combo listPlanDeEstudios.
               {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
                (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
                "select new ve.usb.cohesion.runtime.Pair(carrera, idPlan) " + 
                "from PlanDeEstudios").list();
                list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
                fFOferta.setListPlanDeEstudios(list);
               }
             //Feed for combo listRequisitos.
               {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
                (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
                "select new ve.usb.cohesion.runtime.Pair(asignatura.codigo, idRequisito) " + 
                "from Requisitos").list();
                list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
                fFOferta.setListRequisitos(list);
               }
             }

            request.getSession().setAttribute("idOferta", oferta.getIdOferta());

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        }
        return mapping.findForward(salida);
    }



}